<template>
  <div class="list-page">
    <div class="list-block">
      <page-list-block ref :title-list="pageTitle" :is-point="isPoint" :data-list="dataList" :list-pages="listPages" :list-total="listTotal"></page-list-block>
    </div>
      <float-block :is-float="isFloat" :is-show-calendar="showCalendar" :is-show-link="isShowLink" :mainTitle="mainTitle"
                   :is-point="isPoint"></float-block>
  </div>
</template>

<script>
import FloatBlock from '../../components/float-block/float-block'
import PageListBlock from '../../components/page-list-block/page-list-block'

//接口引入
import {getPageData,getMost} from '@/api/page'
export default {
  name: "list-page",
  components: {
    FloatBlock,
    PageListBlock
  },
  data() {
    return {
      pageType: '',    //页面标识
      pageTitle: '',   //页面标题
      navList: [
        {name: '首页', pathName: 'minHome'},
        {name: '通知通告', pathName: 'notice',classId:'tztg'},
        {name: '教培动态', pathName: 'trends',classId:'jpdt'},
        {name: '教育科研', pathName: 'education',classId:'wztj',
            list: [{name: '科研动态', id: '0',classId:'wztj_kydt'}, {name: '课题研究', id: '1',classId:'wztj_ktgl'}, {name: '学习资源', id: '2',classId:'wztj_wztj'}, {name: '学校科研', id: '3',classId:'wztj_jksjs'}, {name: '教师科研', id: '4',classId:'wztj_jsgrkt'},]},
        {name: '教学研究', pathName: 'teaching',classId:'xxgk',
            list: [{name: '教研动态', id: '0',classId:'xxgk_jxjs'}, {name: '课程改革', id: '1',classId:'xxgk_kcjs'}, {name: '主题研究', id: '2',classId:'xxgk_ktzs'}, {name: '教研论坛', id: '3',classId:'xxgk_jylt'}, {name: '计划总结', id: '4',classId:'xxgk_jycx'}]},
        {name: '教师培训', pathName: 'train',classId:'jsky',
            list: [{name: '培训动态', id: '0',classId:'sxdt'}, {name: '培训管理', id: '1',classId:'sxgl'}, {name: '专题培训', id: '2',classId:'ztpx'}, {name: '网络培训', id: '3',classId:'wlpx'}, {name: '校本研究', id: '4',classId:'xbyx'},]},
        {name: '现代教育技术', pathName: 'technology',classId:'spxw',
            list: [{name: '最新动态', id: '0',classId:'spxw_hdbd'}, {name: '应用研究', id: '1',classId:'spxw_ktyj'}, {name: '技术前沿', id: '2',classId:'spxw_jsqy'}]},
        {name: '心理教育', pathName: 'psychology',classId:'gzz',
            list: [{name: '最新信息', id: '0',classId:'zxxx'}, {name: '心理培训', id: '1',classId:'xlpx'}, {name: '心理研究', id: '2',classId:'xlyj'}, {name: '心理咨询', id: '3',classId:'xlzx'}]},
        {name: '家长学校', pathName: 'parent',classId:'jzxx',
            list: [{name: '活动传真', id: '0',classId:'jzxx_hdcz'}, {name: '主题研究', id: '1',classId:'jzxx_ztyj'}, {name: '学习资源', id: '2',classId:'jzxx_xxzy'}, {name: '计划总结', id: '3',classId:'jzxx_jhzj'}]},
        {name: '远程教育', pathName: 'remote',classId:'ycjy'},
        {name: '研训动态', pathName: 'research',classId:'jyky'},
          {name: '学科通知', pathName: 'subject',classId:'tztg'},
          {name: '课程资源', pathName: 'resources',classId:'kczy'},
      ],
      showCalendar: true,
      isFloat: false,
      isPoint: false,
      isShowLink: false,
      mainTitle: '最多游览',
        listParams:{
            current:1,
            size:30,
            type:'',      //一级标识
            xl:''         //子标识
        },
        dataList:[],      //主体列表数据
        listTotal:0,
        listPages:0,
    }
  },
  created() {
    this.init()
  },
  watch: {
    $route() {
        this.listParams={
            current:1,
            size:30,
            type:'',      //一级标识
            xl:''         //子标识
        };
      this.init()
    }
  },
  methods: {
    /**
     * 初始化处理页面
     */
    init() {
        this.pageType = this.$route.query.pageType;
        let list = [];
        //一级列表页面直接type赋值
        if(this.pageType !== 'subject' && this.pageType !== 'resources'){
            let index = this.navList.findIndex(item => {
                return item.pathName === this.pageType
            });
            this.listParams.type = this.navList[index].classId;
            if(this.navList[index].list && this.navList[index].list.length>0){
                this.listParams.xl = this.navList[index].list[0].classId
            }
        }else{
            //二级列表页面 从路由中获取type赋值
            this.listParams.type = this.$route.query.firstId;
            this.listParams.xl = this.navList.find(item => {
                return item.pathName === this.pageType
            }).classId;
        }

        if (this.pageType === 'education' || this.pageType === 'teaching' || this.pageType === 'train' || this.pageType === 'technology' || this.pageType === 'psychology' || this.pageType === 'parent') {
            list = this.navList.find(item => {
                return item.pathName === this.pageType
            }).list;

            this.isPoint = true;

            this.mainTitle = '通知通告'
            if (this.pageType === 'psychology' || this.pageType === 'parent') {
                this.isShowLink = false;
            } else {
                this.isShowLink = true;
            }

        } else {
            let name = this.navList.find(item => {
                return item.pathName === this.pageType
            }).name;
            list = [{name: name, id: '0'}]
            this.isPoint = false;
            this.isShowLink = false;
            this.mainTitle = '最多游览'
        }
        this.pageTitle = list

        //判断是否展示日历
        if (this.pageType === 'notice' || this.pageType === 'trends') {
            this.showCalendar = true
        } else {
            this.showCalendar = false
        }
        //判断是否浮动
        if (this.pageType === 'remote' || this.pageType === 'research') {
            this.isFloat = true
        } else {
            this.isFloat = false
        }
        this.getData();
    },
    /**
     * 获取数据
     */
    getData(date) {
      // console.log(date);
        let navList = this.navList,
            params = this.listParams;
        if(date&&!this.$utils.isEmpty(date)){
            params.deploydate = date
        }
        if(this.$utils.isEmpty(params.xl)){
            delete params.xl
        }
        getPageData(params).then(res =>{
            if(res.code == 200){
                this.dataList = res.data.records;
                this.listPages = res.data.pages;
                this.listTotal = res.data.total
            }
        })
    },
      /**
       * 获取最多浏览
       */
      getMoreList(){
          getMost(this.listParams).then(res =>{
              if(res.code == 200){

              }
          })
      },
      /**
       * 改变二级标签
       * @param list
       * @param index
       */
      checkTip(list,index){
          this.listParams.current = 1;
          this.listParams.xl=list[index].classId;
          this.dataList = [];
          this.getData()
      },
      /**
       * 列表翻页
       * @param val
       */
      pageCurrentChange(val){
          this.listParams.current = val;
          this.getData()
      },
      /**
       * 标签分类
       * @param info
       */
      changeListType(info){
          if(info){
              this.listParams.label = true;
              // this.
              if(info.subclassid && !this.$utils.isEmpty(info.subclassid)){
                  this.listParams.xl = info.subclassid
              }else{
                  delete this.listParams.xl
              }
          }else{
              this.listParams.label = false;
              delete this.listParams.xl
          }
          this.getData()
      }
  }
}
</script>

<style lang="scss" src="./index.scss" scoped>

</style>
